using Riba.MVVMSL;

namespace TestGUI
{
	public class ChildWindow1ViewModel : ViewModelBase
	{
		public RelayCommand CommandOk { get; private set; }

		private string _displayText;
		public string DisplayText
		{
			get { return _displayText; }
			set { SetPropertyValue(ref _displayText, value, () => DisplayText); }
		}

		public ChildWindow1ViewModel()
		{
			CommandOk = new RelayCommand(OnCommandOK) {IsEnabled = true};

			ExchangeDataAvailable += ChildWindow1ViewModel_ExchangeDataAvailable;
			ChildWindowClosed += ChildWindow1ViewModel_ChildWindowClosed;
		}

		void ChildWindow1ViewModel_ChildWindowClosed(object sender, ChildWindowClosedEventArgs e)
		{
			RaiseShowMsgBox(new ShowMsgBoxEventArgs(string.Format("DialogResult={0}", e.DialogResult), ""));
		}

		void ChildWindow1ViewModel_ExchangeDataAvailable(object sender, ExchangeDataAvailableEventArgs e)
		{
			DisplayText = ExchangeData.ToString();
			((MainPageViewModel)e.ParentVM).Status = "hello from ChildWindow1ViewModel";
		}

		private void OnCommandOK(object handler)
		{
			Callback(this, DisplayText);
			RaiseCloseChildWindowView();
		}
	}
}